home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
admin
/
linuxcon.000
/
linuxcon
/
linuxconf-1.6
/
userconf
/
shells.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-22
|
1KB
|
76 lines
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include "../paths.h"
#include "../misc/misc.h"
#include "userconf.h"
static char **tb;
static int nb;
static void shells_read ()
{
if (tb == NULL){
/* #Specification: userconf / /etc/shells & getusershell()
Shells available to configure user accounts are defined
by getusershell() (which reads /etc/shells optionnally).
It is assumed that the first entry in /etc/shells is the default
shell (When the field is empty in /etc/passwd).
*/
tb = (char**)malloc_err(100*sizeof(char*));
char *pt;
while ((pt=getusershell())!=NULL){
tb[nb++] = strdup(pt);
}
}
}
/*
Return != 0 if a path is an accepted shell
*/
int shells_isok(const char *path)
{
shells_read();
int ret = 0;
if (path[0] == '\0'){
ret = 1;
}else{
for (int i=0; i<nb; i++){
if (strcmp(tb[i],path)==0){
ret = 1;
break;
}
}
}
return ret;
}
int shells_exist (const char *path)
{
struct stat sstat;
int ret = 0;
if (path[0] == '\0'){
ret = 1;
}else{
if (stat(path,&sstat)!=-1
&& S_ISREG(sstat.st_mode)
&& sstat.st_mode & 1){
ret = 1;
}
}
return ret;
}
/*
Return the path of the default shell for normal user.
*/
const char *shells_getdefault()
{
shells_read();
return tb[0];
}